package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.Unknown;

/**
 * https://leetcode.com/problems/remove-linked-list-elements/
 * */
public class LC203  implements Unknown {
    public ListNode removeElements(ListNode head, int val) {
        if (head == null) return null;
        ListNode dummyHead = new ListNode();
        dummyHead.next = head;
        ListNode pre = dummyHead;
        while (head !=null) {
            if (head.val == val) {
                pre.next  = head.next;
            } else {
                pre = pre.next;
            }
            head = head.next;
        }
        return dummyHead.next;
    }
}
